package cn.wolfcode.luowowo.query;

import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;

import java.io.Serializable;

@Data
public class QueryObject implements Serializable {
    private int currentPage = 1;
    private int pageSize = 10;
    private String keyword;
    private Pageable pageable;
    public Pageable getPageable() {
        if (pageable == null) {
            PageRequest pageable = PageRequest.of(currentPage - 1, pageSize, Sort.Direction.ASC, "_id");
            return pageable;
        }
        return pageable;
    }

    public String getKeyword() {
        return StringUtils.hasLength(keyword) ? keyword : null;
    }
}
